package io.renren.modules.convenienceSer.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.convenienceSer.entity.ConvenienceInfoEntity;
import io.renren.modules.convenienceSer.service.ConvenienceInfoService;
import io.renren.modules.news.entity.TopicEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.URLDecoder;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("convenienceSer/convenienceInfo")
public class ConvenienceInfoController {

    @Autowired
    private ConvenienceInfoService convenienceInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("convenienceSer:convenienceInfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ConvenienceInfoEntity> topicList = convenienceInfoService.queryList(query);
        int total = topicList.size();
        PageUtils pageUtil = new PageUtils(topicList, total, query.getLimit(), query.getCurrPage());
//		PageUtils pageUtil = topicService.queryPage(params);
        return R.ok().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("convenienceSer:convenienceInfo:info")
    public R info(@PathVariable("id") Integer id) {
        ConvenienceInfoEntity convenienceInfoEntity = convenienceInfoService.queryObject(id);

        return R.ok().put("convenience", convenienceInfoEntity);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("convenienceSer:convenienceInfo:update")
    public R update(@RequestBody ConvenienceInfoEntity convenienceInfoEntity) {

        convenienceInfoEntity.setContent(URLDecoder.decode(convenienceInfoEntity.getContent()));

        System.out.print("update-----" + convenienceInfoEntity.getContent());
        convenienceInfoService.update(convenienceInfoEntity);
        return R.ok();
    }
}
